package com.cgycms.webdeploy.common;

import com.cgycms.webdeploy.storage.DeployConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

import javax.servlet.MultipartConfigElement;

/**
 * @ClassName : UploadConfig
 * @Description : 上传配置
 * @Author : 王力超
 * @Date: 2020-11-05 15:10
 */
@Configuration
public class UploadConfig {

    @Autowired
    private DeployConfig deployConfig;

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize(DataSize.of(100, DataUnit.MEGABYTES));
        factory.setMaxRequestSize(DataSize.of(100, DataUnit.MEGABYTES));
        factory.setLocation(deployConfig.getUploadTemp());
        return factory.createMultipartConfig();
    }
}
